﻿using System;
using System.Collections.Generic;
using System.Threading;
using EstimateTracker;
using EstimateTracker.ViewModels;
using NUnit.Framework;
using Timer = System.Timers.Timer;

namespace Estimate.ViewModels.Tests
{
    [TestFixture]
    public class ToggleTimerTest
    {
        [Test]
        public void Toggle_WithStartToggleTimerAndTwoSecondPeriod_DisplaysTwoSecondResult()
        {
            // Arrange
            Timer t = new Timer(1000);
            IToggleTimer toggleTimer = new StartToggleTimer(t, d => { }, n => { });

            // Act
            string label = toggleTimer.Label;
            Assert.That(label,Is.EqualTo("Stop"));
            toggleTimer = toggleTimer.Toggle();

            Thread.Sleep(3500);

            double time = toggleTimer.Time;
            label = toggleTimer.Label;
            toggleTimer = toggleTimer.Toggle();

            Assert.That(time,Is.EqualTo(3));
            Assert.That(label, Is.EqualTo("Start"));

            label = toggleTimer.Label;
            Assert.That(label, Is.EqualTo("Stop"));
            toggleTimer = toggleTimer.Toggle();

            Thread.Sleep(3500);

            time = toggleTimer.Time;
            label = toggleTimer.Label;
            toggleTimer.Toggle();

            Assert.That(time, Is.EqualTo(3));
            Assert.That(label, Is.EqualTo("Start"));
        } 
    }
}